package cn.tedu.smartos.entertainment.controller;

import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.entertainment.pojo.dto.EntertainmentAddParam;
import cn.tedu.smartos.entertainment.pojo.dto.EntertainmentCategoryAddParam;
import cn.tedu.smartos.entertainment.pojo.vo.EntertainmentCategoryVO;
import cn.tedu.smartos.entertainment.pojo.vo.EntertainmentResourceVO;
import cn.tedu.smartos.entertainment.service.EntertainmentService;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "08.娱乐模块")
@Slf4j
@RestController
@RequestMapping("/api/v1/entertainment/")
public class EntertainmentController {
    @Autowired
    private EntertainmentService entertainmentService;

    @ApiOperation("娱乐分类列表")
    @ApiOperationSupport(order = 10)
    @GetMapping("category/list")
    public JsonResult categoryList(@RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "10") Integer pageSize) {
        log.debug("开始处理【获取娱乐分类列表】的请求,参数{},{},{}",pageNum,pageSize);
        PageInfo<EntertainmentCategoryVO> categoryList = entertainmentService.listCategory(pageNum,pageSize);
        return JsonResult.ok(categoryList);
    }
    @ApiOperation("添加娱乐分类")
    @ApiOperationSupport(order = 20)
    @PostMapping("category/add")
    public JsonResult addCategory(@RequestBody EntertainmentCategoryAddParam addParam) {
        log.debug("开始处理【添加娱乐分类】的请求,参数{}",addParam);
        entertainmentService.addCategory(addParam);
        return JsonResult.ok();
    }
    @ApiOperation("删除娱乐分类")
    @ApiOperationSupport(order = 30)
    @PostMapping("category/delete")
    public JsonResult deleteCategory(@RequestBody List<Integer> categoryIds){
        log.debug("开始处理【删除娱乐分类】的请求,参数{}",categoryIds);
        entertainmentService.deleteCategory(categoryIds);
        return JsonResult.ok();
    }
    @ApiOperation("娱乐分类详情")
    @ApiOperationSupport(order = 35)
    @GetMapping("category/detail")
    public JsonResult categoryDetail(Integer categoryId){
        log.debug("开始处理【娱乐分类详情】的请求,参数{}",categoryId);
        EntertainmentCategoryVO detail = entertainmentService.detailCategory(categoryId);
        return JsonResult.ok(detail);
    }

//————————————————————————————————————————————————————————————————————————————

    /**
     * 娱乐资源
     */
    @ApiOperation("添加娱乐资源")
    @ApiOperationSupport(order = 40)
    @PostMapping("entertainment/add")
    public JsonResult addEntertainment(@RequestBody EntertainmentAddParam addParam) {
        log.debug("开始处理【添加娱乐资源】的请求，参数：{}", addParam);
        entertainmentService.addEntertainment(addParam);
        return JsonResult.ok();
    }
    @ApiOperation("娱乐资源列表")
    @ApiOperationSupport(order = 50)
    @GetMapping("entertainment/list")
    public JsonResult listEntertainment(Integer categoryId,
                                        @RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【获取娱乐资源列表】的请求,参数{},{},{}",categoryId,pageNum,pageSize);
        PageInfo<EntertainmentResourceVO> resourceVOS = entertainmentService.listEntertainment(categoryId,pageNum,pageSize);
        return JsonResult.ok(resourceVOS);
    }
    @ApiOperation("删除娱乐资源")
    @ApiOperationSupport(order = 60)
    @PostMapping("entertainment/delete")
    public JsonResult deleteEntertainment(@RequestBody List<Long> resourceIds){
        log.debug("开始处理【删除娱乐资源】的请求,参数{}",resourceIds);
        entertainmentService.deleteEntertainment(resourceIds);
        return JsonResult.ok();
    }
    @ApiOperation("娱乐资源详情")
    @ApiOperationSupport(order = 70)
    @GetMapping("entertainment/detail")
    public JsonResult detail(Long resourceId){
        log.debug("开始处理【娱乐资源详情】的请求,参数{}",resourceId);
        EntertainmentResourceVO entertainmentResourceVO = entertainmentService.detail(resourceId);
        return JsonResult.ok(entertainmentResourceVO);
    }
}
